package com.tanhua.server.controller;

import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.SettingsVo;
import com.tanhua.domain.vo.UserInfoVo;
import com.tanhua.server.service.SettingService;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 用户设置控制层
 */
@RestController
@RequestMapping("/users")
public class SettingController {

    @Autowired
    private SettingService settingService;

    /**
     * 分页查询黑名单
     */
    @RequestMapping(value = "/blacklist",method = RequestMethod.GET)
    public ResponseEntity queryPageByUserId(@RequestParam(defaultValue = "1") Long page,@RequestParam(defaultValue = "10") Long pagesize) {
        PageResult<UserInfo> pageResult = settingService.queryPageByUserId(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 黑名单删除
     * /blacklist/{uid}: 可以随便写
     */
    @RequestMapping(value = "/blacklist/{uid}", method = RequestMethod.DELETE)
    public ResponseEntity deleteById(@PathVariable("uid") Long blackUserId) {
        settingService.deleteById(blackUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 设置陌生人问题 - 保存 或 修改
     */
    @RequestMapping(value = "/questions", method = RequestMethod.POST)
    public ResponseEntity saveOrUpdateQuestion(@RequestBody Map<String,String> params) {
        String content = params.get("content");//问题内容
        settingService.saveOrUpdateQuestion(content);
        return ResponseEntity.ok(null);
    }
}
